<!--头部公共部分-->
{include file="common/header" /}
<div style="padding:15px;">
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">适用校区</label>
            <div class="layui-input-block">
                <select name="campus_id" lay-search="" lay-verify="required" >
                    <option value="">请选校区</option>
                    {volist name="campus" id="v"}
                    <option value="{$v.id}">{$v['name']}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="course_id" value="{$id}" class="layui-input">
                <input class="layui-btn" lay-submit style="width: 100px;" lay-filter="form" value="保存" readonly>
            </div>
        </div>
    </form>
</div>
<!--底部公共部分-->
{include file="common/footer" /}

<script>
    //JavaScript代码区域
    layui.use(['element', 'form', 'layer', 'laydate'], function () {
        var $ = layui.$,
            element = layui.element,
            form = layui.form,
            layer = layui.layer;

        //监听提交
        form.on('submit(form)', function (data) {
            var field = data.field;
            var isLoad;
            $.ajax({
                url: "{:url('course/campus')}",
                method: "post",
                data: field,
                beforeSend: function () {
                    isLoad = layer.load(0, {
                        shade: false
                    }); //0代表加载的风格，支持0-2
                },
                success: function (result) {
                    if (result.code === 0) {
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            parent.location.href = '{:url("course/configure")}?id=' + result.data;
                        }, 2000);
                    }
                },
                complete: function () {
                    layer.close(isLoad)
                },
                error: function (error) {
                    console.log(error)
                }
            });
            return false;
        });
    });
</script>